﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;

namespace JZNJ.RadioMonitorServer.Core
{
    public class Draw
    {
        DeviceManager device = new DeviceManager();

        //绘制坐标系
        public void DrawCoordinate(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen p = Pens.White;

            int x = 80;
            int y = 80;

            for (int i = 0; i < 10; i++)
            {
                g.DrawLine(p, x, 80, x, 500);
                x = x + 40;
            }

            for (int i = 0; i < 10; i++)
            {
                g.DrawLine(p, 80, y, 500, y);
                y = y + 40;
            }

            PointF nextPt;

            for (int i = 0; i < device.Frequency.Length - 1; i++)
            {
                if (i == 0)
                {
                    nextPt = new PointF(80, 80);
                }
                else
                {
                    nextPt = DrawPoint(i);
                }
                g.DrawLine(Pens.Black, nextPt, DrawPoint(i + 1));
            }
        }

        //绘制点
        private PointF DrawPoint(int i)
        {
            PointF p = new PointF();
            p.X = 80 + i;

            try
            {
                p.Y = Convert.ToSingle(device.Frequency[i].Trim()) * -5;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return p;
        }
    }
}
